#pragma once
#include <dxgi.h>
#include <d3d11.h>
#include <d2d1.h>
#include "xContainer.h"
#include "xUtil.h"

class xDevice
{
public:
	xDevice();
	virtual ~xDevice();
protected:
	IDXGIFactory1			*m_pFactoryDxgi;
	IDXGISwapChain			*m_pSwapChain;
	ID3D11Device			*m_pDevice;
	ID3D11DeviceContext		*m_pContext;
	ID2D1Factory			*m_pFactoryUI;
	IDXGIAdapter1			*m_pAdapter;
	ID3D11DepthStencilView	*m_pDepthStencilView;
	DXGI_SWAP_CHAIN_DESC	m_desc;
public:
	BOOL	EnumAdapters(INT index, IDXGIAdapter1 **ppAdapter, DXGI_ADAPTER_DESC1 *pInfo = NULL);
	BOOL	CreateDevice(IDXGIAdapter1 *pAdapter, DXGI_SWAP_CHAIN_DESC &desc, D3D_FEATURE_LEVEL *pFeatureLevel);
	BOOL	CreateRenderTarget(ID2D1RenderTarget **ppRT);
	BOOL	CreateRenderTarget(ID3D11RenderTargetView **ppRT);	
	UINT	GetMultisample(xContainer &samples);
	BOOL	SetViewPort(INT nPort, FLOAT fTopLeftX, FLOAT fTopLeftY, FLOAT fWidth, FLOAT fHeight, FLOAT fMinDepth = 0.0f, FLOAT fMaxDepth = 1.0f);
	BOOL	CompileShader(LPCWSTR szFile, LPCSTR szFuncName, LPCSTR szProfile, IUnknown **ppShader, ID3DBlob **ppBlob = NULL);
	BOOL	CompileShader(LPCWSTR szFile, LPCSTR szFuncName, LPCSTR szProfile, LPCWSTR szOutputFile);
	BOOL	LoadShader(LPCWSTR szFile, LPCSTR szProfile, IUnknown **ppShader, void **ppBuffer = NULL, DWORD *pSize = NULL);
	BOOL	SetInputLayout(void *pBuffer, UINT size);
	BOOL	SetVertexBuffers(UINT index, void *pBuffer, UINT nBufferSize, UINT stride);
	BOOL	SetVertexShader(ID3D11VertexShader *pShader);
	BOOL	SetPixelShader(ID3D11PixelShader *pShader);
	BOOL	Reset(UINT nSampleCount);
	BOOL	CreateShaderResource(LPCWSTR szFile, xShaderResource **ppShaderRes);
	BOOL	CreateTexture(LPCWSTR szFile, xResource **ppTexture);
	BOOL	ResizeBuffer(UINT width, UINT height);
};

/*
	DXGI_SWAP_CHAIN_DESC sd= {0};
    sd.BufferCount = 1;
    sd.BufferDesc.Width = 640;
    sd.BufferDesc.Height = 480;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = hWnd;
    sd.SampleDesc.Count = 1;
    sd.SampleDesc.Quality = 0;
    sd.Windowed = TRUE;
*/
